package com.gitee.wsl.mathematics.algebraic


/**
 * Represents field without multiplicative and additive identities i.e., algebraic structure with associative, binary,
 * commutative operations [add] and [multiply]; binary operation [divide] as multiplication of left operand by
 * reciprocal of right one.
 *
 * @param T the type of the semifield element.
 */
 interface FieldOps<T> : RingOps<T> {
    /**
     * Division of two elements.
     *
     * @param left the dividend.
     * @param right the divisor.
     * @return the quotient.
     */
     fun divide(left: T, right: T): T

    /**
     * Division of two elements.
     *
     * @receiver the dividend.
     * @param arg the divisor.
     * @return the quotient.
     */
     operator fun T.div(arg: T): T = divide(this, arg)

    override fun binaryOperationFunction(operation: String): (left: T, right: T) -> T = when (operation) {
        DIV_OPERATION -> ::divide
        else -> super.binaryOperationFunction(operation)
    }

     companion object {
        /**
         * The identifier of division.
         */
         const val DIV_OPERATION: String = "/"
    }
}